//
//  KFDEFTNavBarControl.m
//  KFD
//
//  Created by JIRENTIANXIANG on 6/24/15.
//  Copyright © 2015 kfd. All rights reserved.
//

#import "KFDPreferentialActivitiesNavBarTabControl.h"
#import "ui_config.h"

@interface KFDPreferentialActivitiesNavBarTabControl ()

@property (strong,nonatomic) UIButton* underwayButton;
@property (strong,nonatomic) UIButton* finishedButton;
@property (strong,nonatomic) UIView* slider;

@end

@implementation KFDPreferentialActivitiesNavBarTabControl

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame]) {
        CGSize size=frame.size;
        
        self.underwayButton=[UIButton buttonWithType:UIButtonTypeSystem];
        self.underwayButton.frame=CGRectMake(0, 0, 100, size.height);
        self.underwayButton.center=CGPointMake(size.width/2-50, size.height/2);
        [self.underwayButton setTitle:@"正在进行" forState:UIControlStateNormal];
        self.underwayButton.titleLabel.textAlignment=NSTextAlignmentCenter;
        self.underwayButton.titleLabel.textColor=KFD_WHITE;
        self.underwayButton.titleLabel.font=[UIFont boldSystemFontOfSize:19];
        [self.underwayButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        self.underwayButton.tag=1;
        
        self.finishedButton=[UIButton buttonWithType:UIButtonTypeSystem];
        self.finishedButton.frame=CGRectMake(0, 0, 100, size.height);
        self.finishedButton.center=CGPointMake(size.width/2+50, size.height/2);
        [self.finishedButton setTitle:@"已经结束" forState:UIControlStateNormal];
        self.finishedButton.titleLabel.textAlignment=NSTextAlignmentCenter;
        self.finishedButton.titleLabel.textColor=KFDColorRGB(0xee, 0xbb, 0xbf);
        self.finishedButton.titleLabel.font=[UIFont systemFontOfSize:16];
        [self.finishedButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        self.finishedButton.tag=2;
        
        self.slider=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 3)];
        self.slider.center=CGPointMake(self.underwayButton.center.x, 32);
        self.slider.backgroundColor=KFD_WHITE;
        
        [self addSubview:self.underwayButton];
        [self addSubview:self.finishedButton];
        [self addSubview:self.slider];
    }
    return self;
}

-(void)buttonPressed:(UIButton*)sender
{
    __weak typeof(self) weakSelf=self;
    if (self.didSelectTypeAction) {
        weakSelf.didSelectTypeAction(sender.tag);
    }
    UIButton* unSelectedButton=sender==self.underwayButton?self.finishedButton:self.underwayButton;
    [UIView animateWithDuration:0.4 animations:^{
        sender.titleLabel.textColor=KFD_WHITE;
        sender.titleLabel.font=[UIFont boldSystemFontOfSize:19];
        unSelectedButton.titleLabel.textColor=KFDColorRGB(0xee, 0xbb, 0xbf);
        unSelectedButton.titleLabel.font=[UIFont systemFontOfSize:16];
        self.slider.center=CGPointMake(sender.center.x, 32);
    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
